using System.Collections.Generic;
using UnityEngine;

public class Click : MonoBehaviour
{
	private bool touch;

	private float time;

	private List<GameObject> pool;

	[SerializeField]
	private float touchTime;

	[SerializeField]
	private GameObject effect;

	private void Start()
	{
		pool = new List<GameObject>();
	}

	private void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			touch = true;
		}
		if (touch)
		{
			time += Time.deltaTime;
		}
		if (Input.GetMouseButtonUp(0))
		{
			if (time < touchTime)
			{
				Spawn();
			}
			time = 0f;
			touch = false;
		}
	}

	private void Spawn()
	{
		Vector3 position = Camera.main.ScreenToWorldPoint(UnityEngine.Input.mousePosition);
		position.z = 0f;
		GameObject gameObject = pool.Find((GameObject target) => !target.activeInHierarchy);
		if (gameObject != null)
		{
			gameObject.transform.position = position;
			gameObject.SetActive(value: true);
		}
		else
		{
			gameObject = UnityEngine.Object.Instantiate(effect, position, Quaternion.identity);
			pool.Add(gameObject);
		}
	}
}
